from django import forms
from web.forms.bootstrap import  BootstrapForm
from web import models

class IssueModelForm(BootstrapForm,forms.ModelForm):
    class Meta:
        model=models.Issues
        exclude=['creator','project','create_datetime','latest_update_datetime']
        widgets={
            'priority':forms.Select(attrs={'class':'selectpicker'}),
            "attention": forms.SelectMultiple(attrs={'class': "selectpicker", "data-live-search": "true", "data-actions-box": "true"}),
            'assign':forms.Select(attrs={'class': "selectpicker", "data-live-search": "true"}),
            "start_date": forms.DateTimeInput(attrs={'autocomplete': "off"}),
            "end_date": forms.DateTimeInput(attrs={'autocomplete': "off"})
        }
    def __init__(self,request,*args,**kwargs):
        super().__init__(*args,**kwargs)
        self.request=request
        #问题类型
        self.fields['issues_type'].choices=models.IssuesType.objects.filter(project=request.tracer.project).values_list('id','title')
        #问题模块
        module_list=[('','没有选中任何选项')]
        moduleobject=models.Module.objects.filter(project=request.tracer.project).values_list('id','title')
        module_list.extend(moduleobject)
        self.fields['module'].choices=module_list
        #指派人 & 问题关注人
        total_user_list=[(request.tracer.project.creator_id,request.tracer.project.creator.username),]
        project_user_list=models.ProjectUser.objects.filter(project=request.tracer.project).values_list('user_id','user__username')
        total_user_list.extend(project_user_list)
        self.fields['assign'].choices=[('','没有选中任何选项')]+total_user_list

        self.fields['attention'].choices=total_user_list
        #父问题
        parent_list=[('','没有选中任何选项')]
        parent_obj=models.Issues.objects.filter(project=request.tracer.project).values_list('id','subject')
        parent_list.extend(parent_obj)
        self.fields['parent'].choices=parent_list

class IssueReplayModel(forms.ModelForm):
    class Meta:
        model=models.IssuesReply
        fields=['content','reply']


class InviteModelForm(BootstrapForm,forms.ModelForm):
    '''
    生成邀请码的
    '''
    class Meta:
        model=models.ProjectInvite
        fields=['period','count']